package ru.budget.mobile

import android.app.Application
import android.app.NotificationChannel
import android.app.NotificationManager
import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.startKoin
import org.koin.core.logger.Level
import org.koin.core.logger.Logger
import ru.budget.mobile.di.dataModule
import ru.budget.mobile.di.databaseModule
import ru.budget.mobile.di.domainModule
import ru.budget.mobile.di.viewModelsModule
import ru.budget.mobile.ui.base.MyWork
import java.util.concurrent.TimeUnit

class MainApplication: Application() {

    private val myWorkRequest = PeriodicWorkRequestBuilder<MyWork>(
        repeatInterval = 15,
        repeatIntervalTimeUnit = TimeUnit.MINUTES,
        flexTimeInterval = 15,
        flexTimeIntervalUnit = TimeUnit.MINUTES
    ).build()

    override fun onCreate() {
        super.onCreate()
        //notification()
        //WorkManager.getInstance(applicationContext).enqueue(myWorkRequest)

        startKoin {
            androidLogger(Level.DEBUG)
            androidContext(applicationContext)
            modules(
                databaseModule,
                viewModelsModule,
                domainModule,
                dataModule
            )
        }
    }

    private fun notification() {
        val notificationChannel = NotificationChannel(
            "main_notify",
            "mainNotify",
            NotificationManager.IMPORTANCE_HIGH
        )
        val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
        notificationManager.createNotificationChannel(notificationChannel)
    }
}